package com.jiankangjin.weixinchannel.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;



import com.jiankangjin.weixinchannel.util.ResponseHandler;

/**
 * 【微信公众号支付】用户维权系统及接口说明V1.6
 */
@Controller
@RequestMapping(value="/wx")
public class PayfeedbackController {
	private static final Log logger=LogFactory.getLog(PayfeedbackController.class);
	
	/**
	 * 接收微信维权通知的接口
	 */
	@RequestMapping(value="/legal_right", method=RequestMethod.POST)
	@ResponseBody
	public String payfeedback(HttpServletRequest request, HttpServletResponse response) {
		try {
			ResponseHandler resHandler = new ResponseHandler(request, response);
			logger.info("维权XML参数:"+resHandler.xmlMap);
			String MsgType = resHandler.xmlMap.get("MsgType");
			if (resHandler.isWXPayFeedbackSign()) {
				logger.info("微信签名SHA1验证成功");
				if ("request".equals(MsgType)) {
					logger.info("消息类型为：用户新增投诉...");
				} else if ("confirm/reject".equals(MsgType)) {
					logger.info("消息类型为：用户确认处理完毕投诉...");
				} else {
					logger.info("消息类型为：未知类型投诉...");
				}
			} else {
				logger.error("微信签名SHA1验证失败");
			}
		} catch (Exception e) {
			logger.error(this, e);
		}
		return "fail";
	}
}
/*
 * AppId=wxcec8863ae602c67c, 
 * TimeStamp=1411006373, 
 * OpenId=obDekuBWSsFOzgcXqwRamlEA26BI, 
 * AppSignature=f29f2566a20eeacf7aaf99330a249eea95c489f4, 
 * MsgType=request, 
 * FeedBackId=13304820136356079871, 
 * TransId=1220586901201409023353364774
 * Reason=没有收到货品, 
 * Solution=退款，并不退货, 
 * ExtInfo=fjjxndjdididff 13161619161, 
 * SignMethod=sha1, 
 * 
 * 
 * AppId=wxcec8863ae602c67c, 
 * AppSignature=1408399b5a571bdaeee1b9e6035857f49b35f0aa, 
 * ExtInfo=cjfndndbf 13161613631, 
 * FeedBackId=13304820136356080028, 
 * MsgType=request, 
 * OpenId=obDekuBWSsFOzgcXqwRamlEA26BI, 
 * Reason=没有收到货品, 
 * SignMethod=sha1, 
 * Solution=补发货给我, 
 * TimeStamp=1411010365, 
 * TransId=1220586901201409013211875825
 */
